define(function (require, exports, module) {
    var Form = require("form");
    var store = require("store");

    module.exports = {
        initComponent: function (widget) {
            var form = new Form({
                parentNode: ".J-form",
                model: {
                    id: "form",
                    layout: "2_1",
                    saveaction: function () {
                        var data = form.getData();
                        data.creator = store.get("user").pkUser;
                        data.organization = store.get("user").organization.pkOrganization;
                        widget.service.save(data, function () {
                            widget.get("grid").refresh();
                            widget.toList();
                        })
                    },
                    cancelaction: function () {
                        widget.toList();
                    },
                    items: [{
                        name: "pkProductBatch",
                        type: "hidden"
                    }, {
                        name: "version",
                        type: "hidden",
                        defaultValue: 0
                    }, {
                    	name: "seal",
                    	type: "hidden",
                    	defaultValue: "false"
                    },{
                        name: "name",
                        label: "批次名称",
                        validate: ["required"]
                    }, {
                        name: "product",
                        label: "产品名称",
                        type: "select",
                        url: "api/product/query",
                        keyField: "pkProduct",
                        valueField: "name",
                        validate: ["required"]
                    }, {
                        name: "creatorName",
                        label: "创建人",
                        readonly: true,
                        defaultValue: store.get("user").name
                    }, {
                        name: "createDate",
                        label: "创建时间",
                        type: "date",
                        readonly: true,
                        defaultValue: moment().format("YYYY-MM-DD")
                    }, {
                        name: "description",
                        label: "备注",
                        type: "textarea",
                        "break": true,
                        exValidate: function(value){
                            if(value.length > 512){
                                return "长度不能超过512个字符";
                            }else{
                                return true;
                            }
                        }
                    }]
                }
            });
            widget.set("form", form);
        }
    };
});